package org.csu.wuliu.controller;

import org.csu.wuliu.domain.Item;
import org.csu.wuliu.domain.Supplier;
import org.csu.wuliu.domain.Warehouse;
import org.csu.wuliu.service.SupplierService;
import org.csu.wuliu.service.WarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ware/")
public class WarehouseController {

    @Autowired
    private WarehouseService warehouseService;


    //[
//    {
//        "warehouseId": "仓库1",
//        "address": "上海世界之窗",
//        "type": 1,
//        "substationId": "sh",
//        "totalCapacity": 1000
//    }
//]

    @ResponseBody
    @GetMapping("warehouse")
    public List<Warehouse> getwareList()  {
        System.out.println("进入");
        List<Warehouse> warehouses = warehouseService.getWarehouseList();
        if(warehouses== null){System.out.println("kong");}
        return warehouses;
    }

    @ResponseBody
    @DeleteMapping("warehouse")
    public String deleteware(@RequestParam String warehouseId)  {
        System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!"+warehouseId);
        warehouseService.deleteWarehouse(warehouseId);
        return "成功";
    }

        /*请求体
    {
        "warehouseId": "2",
            "address": "YueLu Street",
            "type": 1,
            "substationId": "cs",
            "totalCapacity": 1000
    }*/

    @PostMapping("warehouse")
    public String newware(@RequestBody Warehouse warehouse)  {
        System.out.println("7777777777777777777777777777777777"+warehouse.getWarehouseId());
        warehouseService.insertWarehouse(warehouse);
        return "成功";
    }

    @PatchMapping("warehouse")
    public String updateware(@RequestBody Warehouse warehouse){
        warehouseService.updateWarehouse(warehouse);
        System.out.println(warehouse.getWarehouseId());
        System.out.println(warehouse.getSubstationId());
        return "成功";
    }

    /* 响应体
[
{
    "itemId": "3",
    "name": "item3",
    "warehouseId": "2",
    "stock": 1000,
    "space": 20,
    "supplierId": "1",
    "productId": "1",
    "username": "wunanxi",
    "categoryId": "1",
    "purchase": "20.0",
    "listprice": "80.0"
}
]
 */
    @ResponseBody
    @GetMapping("warestock")
    public List<Item> getitemListByware(@RequestParam String warehouseId)  {

        List<Item> items = warehouseService.getItemByWarehouseId(warehouseId);
        if(items== null){System.out.println("kong");}
        return items;
    }
}
